<!DOCTYPE html>
<html>

<head>

    {include file="Public/header"}
    <link href="__STATIC__/layout/css/plugins/summernote/summernote.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px
        }
    </style>
</head>

<body style="color:#333;padding:3px;" class="gray-bg">
<!-- 标题 -->
<div class="page-heade">
    <h2 class="title_color text-center">渠道优惠政策申请</h2>
</div>
<!-- 标题 -->
<div class="row-margin-top">

        <input type="hidden" name="id" value="{if isset($data)}{$data.id}{/if}">
        <table class="table-bordered table t_table text-center">
            <tr>
                <td style="min-width: 180px;width: 180px"><label for="">主题<span class="colorRed">*</span>：</label></td>
                <td colspan="5" class="text-left"><input type="text" class="form-control"
                                                         style="min-width: 300px;width: 300px" name="title" value="{if isset($data)}{$data.title}{/if}"></td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px"><label for="">申请人</label></td>
                <td class="text-left">{$em_name}<input type="hidden" name="sqr" value="{$sqr}" /></td>
                <td style="min-width: 180px;width: 180px"><label for="">所属部门</label></td>
                <td class="text-left">{$ssbm}<input type="hidden" name="ssbm" value="{$ssbm_id}"></td>
                <td style="min-width: 180px;width: 180px"><label for="">申请时间</label></td>
                <td class="text-left">{if isset($data)}{$data.sqtime}{else}{:date('Y-m-d')}{/if}<input type="hidden" name="sqtime" value="{if isset($data)}{$data.sqtime}{else}{:date('Y-m-d')}{/if}"></td>
            </tr>
          <!--  <tr>
                <td style="min-width: 180px;width: 180px"><label for="">使用角色<span class="colorRed">*</span>：</label></td>
                <td colspan="5" class="text-left">
                    <select name="" id="">
                        <option value="">请选择</option>
                        {volist name="syjs" id="row"}
                        <option value="{$row.id}">{$row.role_name}</option>
                        {/volist}
                    </select>
                    请选择使用哪个角色提交该申请，审批流程会根据选择的角色提交到对应的上级领导。
                </td>
            </tr>-->
            <tr>
                <td style="min-width: 180px;width: 180px"><label for="">申请原因及其他说明</label></td>
                <td colspan="5" class="text-left">
                    <div class="ibox float-e-margins" style="margin-bottom: 0">
                        <div class="ibox-content no-padding">
                            <div class="summernote" id="info" >
                                {if isset($data)}{$data.info}{/if}
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>

        <div class="ibox">
            <input type="button" class="btn btn-outline btn-default tjcxfa" value="添加促销方案">
        </div>

        <div id="cxfa_wrap">
            {if isset($fa)}
            {volist name="fa" id="row" key="k"}
            <form action="" class="form-inline">
            <table class="table-bordered table t_table fxfa hideit" data-i="{$k}">
                <input type="hidden" name="fa_id" value="{$row.id}">
                <tr class="title_color">
                    <th style="min-width: 180px;width: 180px">促销方案{$k}</th>
                    <th colspan="3">
                        <a href="javascript:;" class="shch">删除</a>
                        <a href="javascript:;" class="bc" style="display: none;">保存</a>
                        <a href="javascript:;" class="bj">编辑</a>
                    </th>
                </tr>
                <tr>
                    <td>是否整单<span class="colorRed">*</span></td>
                    <td>
                        <label for=""><input type="radio" name="sfzd_{$k}" class="sfzd" value="1" {if $row.sfzd==1}checked{/if} disabled>是</label>
                        <label for=""><input type="radio" name="sfzd_{$k}" class="sfzd" value="0" {if $row.sfzd==0}checked{/if} disabled>否</label>
                    </td>
                    <td>
                        优惠时间段<span class="colorRed">*</span>
                    </td>
                    <td>
                        <div class="form-group">
                            <input type="text" class="form-control layer-date start"  style="display: inline-block;" name="start" value="{$row.start}" onclick="laydate({
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
    })" disabled>
                        </div>
                        <div class="form-group">
                            至
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control layer-date end" style="display: inline-block;" name="end" value="{$row.end}" onclick="laydate({
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
    })" disabled>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销区域<span class="colorRed">*</span>：</label></td>
                    <td colspan="3">
                        <div style="float:left;">
                            <label class="radio-inline">
                                <input type="radio" name="area_{$k}" class="area" value="1" {if $row.area==1}checked{/if} disabled>分区
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_{$k}" class="area" value="2" {if $row.area==2}checked{/if} disabled>省份
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_{$k}" class="area" value="3" {if $row.area==3}checked{/if} disabled>城市
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_{$k}" class="area" value="4" {if $row.area==4}checked{/if} disabled>经销商
                            </label>
                        </div>
                        <div style="width:300px;float:left;">
                            <div class="input-group">
                                <input class="area_id" type="text" placeholder="请输入关键字或空格查询"
                                       class="form-control" value="" style="min-width: 300px;width: 300px;display: none;" >
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <a href="javascript:;" style="float:left;margin-left:10px;display: none;" class="btn btn-primary select_area">选择</a>
                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;display: none;" >清空</button>
                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-right" >您选择的<span class="xuanding_name">{if $row.area==2}省份{elseif $row.area==3}城市{elseif $row.area==4}经销商{else}分区{/if}</span><span class="colorRed">*</span>：</td>
                    <td colspan="3">
                        <div class="duoxuan">

                            {volist name="row.area_id" id="row2"}
                            <span class="ren" data-id="{$row2.id}">{$row2.area_name}<input type="hidden" name="area_id[]" value="{$row2.id}"><span class="close" style="display: none;">×</span></span>
                            {/volist}

                        </div>
                    </td>
                </tr>
                <tr class="pro" {if $row.sfzd==1}style="display:none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销产品<span
                            class="colorRed">*</span>：</label></td>
                    <td colspan="3">
                        <div style="float:left;">
                            <label class="radio-inline">
                                <input disabled type="radio" name="product_{$k}" class="product" id="" value="1" {if $row.product==1}checked{/if}>品牌
                            </label>
                            <label class="radio-inline">
                                <input disabled type="radio" name="product_{$k}" class="product" id="" value="2" {if $row.product==2}checked{/if}>品类
                            </label>
                            <label class="radio-inline">
                                <input disabled type="radio" name="product_{$k}" class="product" id="" value="3" {if $row.product==3}checked{/if}>系列
                            </label>
                            <label class="radio-inline">
                                <input disabled type="radio" name="product_{$k}" class="product" id="" value="4" {if $row.product==4}checked{/if}>SKU
                            </label>
                            <label class="radio-inline">
                                <input disabled type="radio" name="product_{$k}" class="product" id="" value="5" {if $row.product==5}checked{/if}>单品
                            </label>
                        </div>
                        <div style="width:300px;float:left;">
                            <div class="input-group">
                                <input class="product_id" type="text" placeholder="请输入关键字或空格查询"
                                       class="form-control" value="" style="min-width: 300px;width: 300px;display: none;" >
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <a href="javascript:;" style="float:left;margin-left:10px;display: none;" class="btn btn-primary select_product">选择</a>
                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;display: none;" >清空</button>
                    </td>
                </tr>
                <tr class="pro" {if $row.sfzd==1}style="display:none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-right" >
                        您选择的<span class="xuanding_product">{if $row.product==2}品类{elseif $row.product==3}系列{elseif $row.product==4}SKU{elseif $row.product==5}单品{else}品牌{/if}</span><span class="colorRed">*</span>:
                    </td>
                    <td class="xzd_brand" colspan="3">
                        <div class="duoxuan">
                            {volist name="row.product_id" id="row2"}
                            <span class="ren">{$row2.area_name}<input disabled type="hidden" name="product_id[]" value="{$row2.id}"><span class="close" style="display: none;">×</span></span>
                            {/volist}
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">优惠类型</label><span class="colorRed">*</span>:</td>
                    <td colspan="3">
                        <label for="" class="zdyc" {if $row.sfzd==1}style="display:none;"{/if}><input disabled type="checkbox" name="yhlx[]"  value="3" class="chzk" {if in_array(3,$row.yhlx)}checked{/if}>出货折扣</label>
                        <label for="" class="zdyc" {if $row.sfzd==1}style="display:none;"{/if}><input disabled type="checkbox" name="yhlx[]"  value="4" class="agdjch" {if in_array(4,$row.yhlx)}checked{/if}>按固定价出货</label>
                        <label for="" class="zdyc" {if $row.sfzd==1}style="display:none;"{/if}><input disabled type="checkbox" name="yhlx[]"  value="5" class="shdz" {if in_array(5,$row.yhlx)}checked{/if}>随货搭赠</label>
                        <label for=""><input disabled type="checkbox" name="yhlx[]" value="1" class="shmj" {if in_array(1,$row.yhlx)}checked{/if}>随货满减</label>
                        <label for=""><input disabled type="checkbox" name="yhlx[]" value="2" class="chfd" {if in_array(2,$row.yhlx)}checked{/if}>出货返点</label>
                    </td>
                </tr>
                <tr class="chzk_tr" {if !in_array(3,$row.yhlx)}style="display: none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货折扣</label></td>
                    <td colspan="3">
                        单位：
                        <select name="chzk_unit" class="dw2" disabled>
                            <option value="元" {if $row.chzk_unit=='元'}selected{/if}>元</option>
                            <option value="发运单位"  {if $row.chzk_unit=='发运单位'}selected{/if}>发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="chzk_tr" {if !in_array(3,$row.yhlx)}style="display: none;"{/if}>
                    <td colspan="3">
                        <ul class="unlist">
                            {if $row.chzk_reach}
                            {volist name="row.chzk_reach" id="row2" key="k2"}
                            <li>满 <input disabled type="text" class="form-control" name="chzk_reach[]" value="{$row2}">（<span class="dw2_span">{$row.chzk_unit}</span>） <input disabled name="chzk_down[]" type="text" class="form-control" value="{$row.chzk_down[$k2-1]}">%OFF,&nbsp;&nbsp;限量<input disabled type="text" name="chzk_limit[]" class="form-control" value="{$row.chzk_limit[$k2-1]}">（<span class="dw2_span">{$row.chzk_unit}</span>）
                                {if count($row.chzk_reach)==$k2}
                                <a href="javascript:;" class="btn btn-default delit" style="display: none">-</a>
                                <a href="javascript:;" class="btn btn-default addit" style="display: none">+</a>
                                {elseif count($row.chzk_reach)>$k2&&$k2>1}
                                <a href="javascript:;" class="btn btn-default delit" style="display: none">-</a>
                                {elseif count($row.chzk_reach)==1}
                                <a href="javascript:;" class="btn btn-default addit" style="display: none">+</a>
                                {/if}
                            </li>
                            {/volist}
                            {else}
                            <li>满 <input disabled type="text" class="form-control" name="chzk_reach[]" value="">（<span class="dw2_span">元</span>） <input disabled name="chzk_down[]" type="text" class="form-control" value="">%OFF,&nbsp;&nbsp;限量<input disabled type="text" name="chzk_limit[]" class="form-control" value="">（<span class="dw2_span">元</span>）
                                <a href="javascript:;" class="btn btn-default addit" style="display: none">+</a></li>
                            {/if}
                        </ul>
                    </td>
                </tr>
                <tr class="agdjch_tr" {if !in_array(4,$row.yhlx)}style="display: none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">按固定价出货</label></td>
                    <td colspan="3">
                        单位：
                        <select disabled name="agdjch_unit" class="dw2">
                            <option value="元" {if $row.agdjch_unit=='元'}selected{/if} >元</option>
                            <option value="发运单位" {if $row.agdjch_unit=='发运单位'}selected{/if} >发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="agdjch_tr" {if !in_array(4,$row.yhlx)}style="display: none;"{/if}>
                    <td colspan="3">
                        <ul class="unlist">
                            {if $row.agdjch_reach}
                            {volist name="row.agdjch_reach" id="row2" key="k2"}
                            <li>满 <input disabled type="text" class="form-control" name="agdjch_reach[]" value="{$row2}">（<span class="dw2_span">{$row.agdjch_unit}</span>） 按<input disabled name="agdjch_down[]" type="text" class="form-control" value="{$row.agdjch_down[$k2-1]}">（元/发运单位）出货,&nbsp;&nbsp;限量<input disabled type="text" name="agdjch_limit[]" class="form-control" value="{$row.agdjch_limit[$k2-1]}">（<span class="dw2_span">{$row.agdjch_unit}</span>）<a href="javascript:;" class="btn btn-default addit2" style="display: none">+</a>
                                {if count($row.agdjch_reach)==$k2}
                                <a href="javascript:;" class="btn btn-default delit2" style="display: none">-</a>
                                <a href="javascript:;" class="btn btn-default addit2" style="display: none">+</a>
                                {elseif count($row.agdjch_reach)>$k2&&$k2>1}
                                <a href="javascript:;" class="btn btn-default delit2" style="display: none">-</a>
                                {elseif count($row.agdjch_reach)==1}
                                <a href="javascript:;" class="btn btn-default addit2" style="display: none">+</a>
                                {/if}
                            </li>
                            {/volist}
                            {else}
                            <li>满 <input disabled type="text" class="form-control" name="agdjch_reach[]" value="">（<span class="dw2_span">元</span>） 按<input disabled name="agdjch_down[]" type="text" class="form-control" value="">（元/发运单位）出货,&nbsp;&nbsp;限量<input disabled type="text" name="agdjch_limit[]" class="form-control" value="">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit2" style="display: none">+</a></li>
                            {/if}
                        </ul>
                    </td>
                </tr>
                <tr class="shdz_tr" {if !in_array(5,$row.yhlx)}style="display: none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货搭赠</label></td>
                    <td colspan="3">
                        单位：
                        <select disabled name="shdz_unit" class="dw2">
                            <option value="元" {if $row.shdz_unit=='元'}selected{/if}>元</option>
                            <option value="发运单位" {if $row.shdz_unit=='发运单位'}selected{/if}>发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="shdz_tr" {if !in_array(5,$row.yhlx)}style="display: none;"{/if}>
                    <td colspan="3">
                        <ul>
                            {if $row.shdz_reach}
                            {volist name="row.shdz_reach" id="row2" key="k2"}
                            <li>
                                满 <input disabled type="text" class="form-control" name="shdz_reach[]" value="{$row2}">（<span class="dw2_span">{$row.shdz_unit}</span>） 送赠品：<a href="javascript:;" class="shzhzp" style="display: none;"><input disabled type="hidden" name="shdz_gift[]"  value='{$row.shdz_gift[$k2-1]}'>设置赠品</a>&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="shdz_limit[]" value="{$row.shdz_limit[$k2-1]}">（<span class="dw2_span">{$row.shdz_unit}</span>）
                                {if count($row.shdz_reach)==$k2}
                                <a href="javascript:;" class="btn btn-default delit3" style="display: none">-</a>
                                <a href="javascript:;" class="btn btn-default addit3" style="display: none">+</a>
                                {elseif count($row.shdz_reach)>$k2&&$k2>1}
                                <a href="javascript:;" class="btn btn-default delit3" style="display: none">-</a>
                                {elseif count($row.shdz_reach)==1}
                                <a href="javascript:;" class="btn btn-default addit3" style="display: none">+</a>
                                {/if}
                                <br>
                                <script>
                                    var ckstr="{$row.shdz_gift[$k2-1]}";
                                    if(ckstr!=""){
                                        ckstr = unescape(ckstr)
                                        ckstr = JSON.parse(ckstr)
                                    }
                                    for(var i=0;i<ckstr.length;i++)
                                    document.write('<font color="red">赠品预览:赠品：'+ckstr[i].product_title+';&nbsp;&nbsp;数量:'+ckstr[i].num+';&nbsp;&nbsp;单价:'+ckstr[i].price+'元/'+ckstr[i].unit+';&nbsp;&nbsp;小计:'+ckstr[i].total+'元</font><br>')
                                    
                                    </script>
                                
                            </li>
                            {/volist}
                            {else}
                            <li>
                                满 <input disabled type="text" class="form-control" name="shdz_reach[]" value="">（<span class="dw2_span">元</span>） 送赠品：<a href="javascript:;" class="shzhzp" style="display: none;"><input disabled type="hidden" name="shdz_gift[]"  value=''>设置赠品</a>,&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="shdz_limit[]" value="">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit3" style="display: none">+</a><br>
                                <font color="red">请设置赠品</font>
                            </li>
                            {/if}
                        </ul>
                    </td>
                </tr>
                <tr class="shmj_tr" {if !in_array(1,$row.yhlx)}style="display: none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货满减</label></td>
                    <td colspan="3">
                        单位：
                        <select name="shmj_unit" class="dw1" disabled>
                            <option value="元" <?php if($row['shmj_unit']=='元'): ?>selected<?php endif; ?> >元</option>
                            <option value="发运单位" <?php if($row['shmj_unit']=='发运单位'): ?>selected<?php endif; ?> >发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="shmj_tr" {if !in_array(1,$row.yhlx)}style="display: none;"{/if}>
                    <td colspan="3">
                        <ul>
                            {if $row.shmj_reach}
                            {volist name="row.shmj_reach" id="row2" key="k2"}
                            <li>
                                满 <input disabled type="text" class="form-control" name="shmj_reach[]" value="{$row2}">（<span class="dw1_span">{$row['shmj_unit']}</span>） 减 <input disabled type="text" class="form-control" name="shmj_down[]"  value="{$row.shmj_down[$k2-1]}">（<span class="dw1_span">{$row['shmj_unit']}</span>）,&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="shmj_limit[]"  value="{$row.shmj_limit[$k2-1]}">（<span class="dw1_span">{$row['shmj_unit']}</span>）
                                {if count($row.shmj_reach)==$k2}
                                <a href="javascript:;" class="btn btn-default delit4" style="display: none">-</a>
                                <a href="javascript:;" class="btn btn-default addit4" style="display: none">+</a>
                                {elseif count($row.shmj_reach)>$k2&&$k2>1}
                                <a href="javascript:;" class="btn btn-default delit4" style="display: none">-</a>
                                {elseif count($row.shmj_reach)==1}
                                <a href="javascript:;" class="btn btn-default addit4" style="display: none">+</a>
                                {/if}
                            </li>
                            {/volist}
                            {else}
                            <li>
                                满 <input disabled type="text" class="form-control" name="shmj_reach[]" value="">（<span class="dw1_span">元</span>） 减 <input disabled type="text" class="form-control" name="shmj_down[]"  value="">（<span class="dw1_span">元</span>）,&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="shmj_limit[]"  value="">（<span class="dw1_span">元</span>）<a href="javascript:;" class="btn btn-default addit4" style="display: none">+</a>
                            </li>
                            {/if}
                        </ul>
                    </td>
                </tr>
                <tr class="chfd_tr" {if !in_array(2,$row.yhlx)}style="display: none;"{/if}>
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货返点</label></td>
                    <td colspan="3">
                        单位：
                        <select disabled name="chfd_unit" class="dw2">
                            <option value="元" {if $row.chfd_unit=='元'}selected{/if} >元</option>
                            <option value="发运单位" {if $row.chfd_unit=='发运单位'}selected{/if} >发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="chfd_tr" {if !in_array(2,$row.yhlx)}style="display: none;"{/if}>
                    <td colspan="3">
                        <ul>
                            {if $row.chfd_reach}
                            {volist name="row.chfd_reach" id="row2" key="k2"}
                            <li>
                                满 <input disabled type="text" class="form-control" name="chfd_reach[]" value="{$row2}">（<span class="dw2_span">{$row.chfd_unit}</span>） 减 <input disabled type="text" class="form-control" name="chfd_down[]" value="{$row.chfd_down[$k2-1]}">%,&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="chfd_limit[]"  value="{$row.chfd_limit[$k2-1]}">（<span class="dw2_span">{$row.chfd_unit}</span>）
                                {if count($row.chfd_reach)==$k2}
                                <a href="javascript:;" class="btn btn-default delit5" style="display: none">-</a>
                                <a href="javascript:;" class="btn btn-default addit5" style="display: none">+</a>
                                {elseif count($row.chfd_reach)>$k2&&$k2>1}
                                <a href="javascript:;" class="btn btn-default delit5" style="display: none">-</a>
                                {elseif count($row.chfd_reach)==1}
                                <a href="javascript:;" class="btn btn-default addit5" style="display: none">+</a>
                                {/if}
                            </li>
                            {/volist}
                            {else}
                            <li>
                                满 <input disabled type="text" class="form-control" name="chfd_reach[]" value="">（<span class="dw2_span">元</span>） 减 <input disabled type="text" class="form-control" name="chfd_down[]" value="">%,&nbsp;&nbsp;限量<input disabled type="text" class="form-control" name="chfd_limit[]"  value="">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit5" style="display: none">+</a>
                            </li>
                            {/if}
                        </ul>

                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">方案说明</label></td>
                    <td colspan="3">
                        <div class="ibox float-e-margins" style="margin-bottom: 0">
                            <div class="ibox-content no-padding">
                                <div class="summernote summernote_disabled">
                                    {$row.brief}
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            </table>
            </form>
            {/volist}
            {else}
            <form action="" class="form-inline">
            <table class="table-bordered table t_table fxfa">
                <input type="hidden" name="fa_id">
                <tr class="title_color">
                    <th style="min-width: 180px;width: 180px">促销方案1</th>
                    <th colspan="3">
                        <a href="javascript:;" class="shch">删除</a>
                        <a href="javascript:;" class="bc">保存</a>
                        <a href="javascript:;" class="bj" style="display: none;">编辑</a>
                    </th>
                </tr>
                <tr>
                    <td>是否整单<span class="colorRed">*</span></td>
                    <td>
                        <label for=""><input type="radio" name="sfzd_1" class="sfzd" value="1">是</label>
                        <label for=""><input type="radio" name="sfzd_1" class="sfzd" value="0" checked>否</label>
                    </td>
                    <td>
                        优惠时间段<span class="colorRed">*</span>
                    </td>
                    <td>
                        <div class="form-group">
                            <input type="text" class="form-control layer-date start"  style="display: inline-block;" name="start" value="{if isset($data)}{$data.start}{/if}" onclick="laydate({
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
    })">
                        </div>
                        <div class="form-group">
                            至
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control layer-date end" style="display: inline-block;" name="end" value="{if isset($data)}{$data.end}{/if}" onclick="laydate({
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
    })">
                        </div>
                    </td>
                </tr>

                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销区域<span class="colorRed">*</span>：</label></td>
                    <td colspan="3">
                        <div style="float:left;">
                            <label class="radio-inline">
                                <input type="radio" name="area_1" class="area" value="1" {if (isset($data)&&$data.area==1)||!isset($data)}checked{/if}>分区
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_1" class="area" value="2" {if (isset($data)&&$data.area==2)}checked{/if}>省份
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_1" class="area" value="3" {if (isset($data)&&$data.area==3)}checked{/if}>城市
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="area_1" class="area" value="4" {if (isset($data)&&$data.area==4)}checked{/if}>经销商
                            </label>
                        </div>
                        <div style="width:300px;float:left;">
                            <div class="input-group">
                                <input class="area_id" type="text" placeholder="请输入关键字或空格查询"
                                       class="form-control" value="" style="min-width: 300px;width: 300px">
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <a href="javascript:;" style="float:left;margin-left:10px;" class="btn btn-primary select_area">选择</a>
                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;" >清空</button>
                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-right" id="selected_area">您选择的<span class="xuanding_name">分区</span><span class="colorRed">*</span>：</td>
                    <td id="xuanding" colspan="3">
                        <div class="duoxuan">

                        </div>
                    </td>
                </tr>
                <tr class="pro">
                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销产品<span
                            class="colorRed">*</span>：</label></td>
                    <td colspan="3">
                        <div style="float:left;">
                            <label class="radio-inline">
                                <input type="radio" name="product_1" class="product" id="" value="1" checked>品牌
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="product_1" class="product" id="" value="2" >品类
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="product_1" class="product" id="" value="3" >系列
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="product_1" class="product" id="" value="4" >SKU
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="product_1" class="product" id="" value="5" >单品
                            </label>
                        </div>
                        <div style="width:300px;float:left;">
                            <div class="input-group">
                                <input class="product_id" type="text" placeholder="请输入关键字或空格查询" class="form-control" value="" style="min-width: 300px;width: 300px">
                                <div class="input-group-btn">
                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
                                        <span class="caret"></span>
                                    </button>
                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <a href="javascript:;" style="float:left;margin-left:10px;" class="btn btn-primary select_product">选择</a>
                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;" >清空</button>
                    </td>
                </tr>
                <tr class="pro">
                    <td style="min-width: 180px;width: 180px" class="text-right" id="selected_product">您选择的<span class="xuanding_product">品牌</span><span class="colorRed">*</span>:</td>
                    <td class="xzd_brand" colspan="3">
                        <div class="duoxuan">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">优惠类型</label><span class="colorRed">*</span>:</td>
                    <td colspan="3">
                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="3" class="chzk">出货折扣</label>
                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="4" class="agdjch">按固定价出货</label>
                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="5" class="shdz">随货搭赠</label>
                        <label for=""><input type="checkbox" name="yhlx[]" value="1" class="shmj">随货满减</label>
                        <label for=""><input type="checkbox" name="yhlx[]" value="2" class="chfd">出货返点</label>
                    </td>
                </tr>
                <tr class="chzk_tr" style="display: none;">
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货折扣</label></td>
                    <td colspan="3">
                        单位：
                        <select name="chzk_unit" class="dw2">
                            <option value="元">元</option>
                            <option value="发运单位">发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="chzk_tr" style="display: none;">
                    <td colspan="3">
                        <ul>
                            <li>
                                满 <input type="text" class="form-control" name="chzk_reach[]">（<span class="dw2_span">元</span>） <input name="chzk_down[]" type="text" class="form-control">%OFF,&nbsp;&nbsp;限量<input type="text" name="chzk_limit[]" class="form-control">（<span class="dw2_span">元</span>）
                                <a href="javascript:;" class="btn btn-default addit">+</a>
                            </li>
                        </ul>

                    </td>
                </tr>
                <tr class="agdjch_tr" style="display: none;">
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">按固定价出货</label></td>
                    <td colspan="3">
                        单位：
                        <select name="agdjch_unit" class="dw2">
                            <option value="元">元</option>
                            <option value="发运单位">发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="agdjch_tr" style="display: none;">
                    <td colspan="3">
                        <ul>
                            <li>
                                满 <input type="text" class="form-control" name="agdjch_reach[]">（<span class="dw2_span">元</span>） 按<input name="agdjch_down[]" type="text" class="form-control">（元/发运单位）出货,&nbsp;&nbsp;限量<input type="text" name="agdjch_limit[]" class="form-control">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit2">+</a>
                            </li>
                        </ul>
                    </td>
                </tr>
                <tr class="shdz_tr" style="display: none;">
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货搭赠</label></td>
                    <td colspan="3">
                        单位：
                        <select name="shdz_unit" class="dw2">
                            <option value="元">元</option>
                            <option value="发运单位">发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="shdz_tr" style="display: none;">
                    <td colspan="3">
                        <ul>
                            <li>
                                满 <input type="text" class="form-control" name="shdz_reach[]">（<span class="dw2_span">元</span>） 送赠品：<a href="javascript:;" class="shzhzp"><input type="hidden" name="shdz_gift[]" >设置赠品</a>,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shdz_limit[]">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit3">+</a><br>
                                <font color="red">请设置赠品</font>
                            </li>
                        </ul>
                    </td>
                </tr>
                <tr class="shmj_tr" style="display: none;">
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货满减</label></td>
                    <td colspan="3">
                        单位：
                        <select name="shmj_unit" class="dw1">
                            <option value="元">元</option>
                            <option value="发运单位">发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="shmj_tr" style="display: none;">
                    <td colspan="3">
                        <ul>
                            <li>
                                满 <input type="text" class="form-control" name="shmj_reach[]">（<span class="dw1_span">元</span>） 减 <input type="text" class="form-control" name="shmj_down[]">（<span class="dw1_span">元</span>）,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shmj_limit[]">（<span class="dw1_span">元</span>）<a href="javascript:;" class="btn btn-default addit4">+</a>
                            </li>
                        </ul>

                    </td>
                </tr>
                <tr class="chfd_tr" style="display: none;">
                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货返点</label></td>
                    <td colspan="3">
                        单位：
                        <select name="chfd_unit" class="dw2">
                            <option value="元">元</option>
                            <option value="发运单位">发运单位</option>
                        </select>
                    </td>
                </tr>
                <tr class="chfd_tr" style="display: none;">
                    <td colspan="3">
                        <ul>
                            <li>
                                满 <input type="text" class="form-control" name="chfd_reach[]">（<span class="dw2_span">元</span>） 减 <input type="text" class="form-control" name="chfd_down[]">%,&nbsp;&nbsp;限量<input type="text" class="form-control" name="chfd_limit[]">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit5">+</a>
                            </li>
                        </ul>

                    </td>
                </tr>
                <tr>
                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">方案说明</label></td>
                    <td colspan="3">
                        <div class="ibox float-e-margins" style="margin-bottom: 0">
                            <div class="ibox-content no-padding">
                                <div class="summernote">
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>

            </table>
            </form>
            {/if}
        </div>

        <div class="ibox">
            <input type="button" class="btn btn-outline btn-default tjcxfa" value="添加促销方案">
        </div>

        <table class="table-bordered table t_table text-center">
            <tr>
                <td style="min-width: 180px;width: 180px"><label for="">无政策销量(元)</label><span class="colorRed">*</span></td>
                <td class="text-left"><input type="text" class="form-control numReg" name="saleNum" value="{if isset($data)}{$data.saleNum}{/if}"></td>
                <td style="min-width: 180px;width: 180px"><label for="">政策预计销量(元)</label><span class="colorRed">*</span></td>
                <td class="text-left"><input type="text" class="form-control numReg" name="policySaleNum" value="{if isset($data)}{$data.policySaleNum}{/if}"></td>
                <td style="min-width: 180px;width: 180px"><label for="">销售增量</label></td>
                <td><input type="hidden" name="saleInc" value="{if isset($data)}{$data.saleInc}{/if}"><span id="saleIncSpan">{if isset($data)}{$data.saleInc}{/if}</span></td>
            </tr>
            <tr>
                <td style="min-width: 180px;width: 180px"><label for="">预计搭赠产生的费用(元)</label><span class="colorRed">*</span></td>
                <td class="text-left"><input type="text" class="form-control" name="estiGiftCost" value="{if isset($data)}{$data.estiGiftCost}{/if}"></td>
                <td style="min-width: 180px;width: 180px"><label for="">预计费用率</label></td>
                <td class="text-left"><span id="estiCostRateSpan">{if isset($data)}{$data.estiCostRate}{/if}</span>%<input type="hidden" name="estiCostRate" value="{if isset($data)}{$data.estiCostRate}{/if}"></td>
                <td style="min-width: 180px;width: 180px"><label for="">预计回报率</label></td>
                <td class="text-left"><span id="estiReturnRateSpan">{if isset($data)}{$data.estiReturnRate}{/if}</span>%<input type="hidden" name="estiReturnRate" value="{if isset($data)}{$data.estiReturnRate}{/if}"></td>
            </tr>
        </table>
        <div class="form-group" style="margin:20px 10px 20px 20px;">
            {if isset($attach)}
            <ul class="list-group">
                {volist name="attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.path}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            {/if}
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>
        {if isset($data)}
        {/if}
        <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0">
        {if isset($data)}
            {if $data.status==2}
            <input type="hidden" id="nodeKey" name="nodeKey"/>
                  <input type="hidden" id="selectId" name="selectId"/>
                  <input type="hidden" id="selectName" name="selectName"/>
                    {volist name="btn.nextNodes" id="b"}
                      {if $b.nodeName=='结束'}
                      <input type="button" class="btn-danger btn" onclick="zuofei('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="点此作废"/>
                      {else/}
                      <input type="button" class="btn-info btn" onclick="baocun('{$b.nodeKey}','{$b.selectId}','{$b.selectName}')" value="保存并提交工作流"/>

                      {/if}
                    {/volist}
                    <input type="button" class="btn btn-warning" value="返回" onclick="back()">
            {else/}
                <input type="button" class="btn btn-success save" id="save1" value="保存为草稿">
                <input type="button" class="btn btn-info save" id="save2" value="保存并提交工作流">
                <input type="button" class="btn btn-warning" value="返回" onclick="back()">
            {/if}
        {else}
            <input type="button" class="btn btn-success save" id="save1" value="保存为草稿">
            <input type="button" class="btn btn-info save" id="save2" value="保存并提交工作流">
            <input type="button" class="btn btn-warning" value="返回" onclick="back()">
        {/if}
        </div>

</div>
<!-- 全局js -->
{include file="Public/footer"}
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote.min.js"></script>
<script src="__STATIC__/layout/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="__STATIC__/layout/js/plugins/layer/laydate/laydate.js"></script>
<script src="__STATIC__/layout/js/plugins/suggest/bootstrap-suggest.min.js"></script>
<script>
 

{if isset($data)}
var fr={$from};
function baocun(nodeKey,selectId,selectName){
   // alert(1);
    $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
    var param = {}
        param.title = $('[name=title]').val()
        param.sqr = $('[name=sqr]').val()
        param.ssbm = $('[name=ssbm]').val()
        param.sqtime = $('[name=sqtime]').val()
        param.info = $('#info').code()
        param.saleNum = $('[name=saleNum]').val()
        param.policySaleNum = $('[name=policySaleNum]').val()
        param.saleInc = $('[name=saleInc]').val()
        param.estiGiftCost = $('[name=estiGiftCost]').val()
        param.estiCostRate = $('[name=estiCostRate]').val()
        param.estiReturnRate = $('[name=estiReturnRate]').val()
        param.attach = $('[name=attach]').val()
        param.remove = $('[name=remove]').val()
        param.id = $('[name=id]').val()
        param.nodeKey=nodeKey
        param.selectId=selectId
        param.selectName=selectName
        $("#nodeKey").val(nodeKey)
        $("#selectId").val(selectId)
        $("#selectName").val(selectName)
        $.post("{:url('baocunchuli')}",param,function(re){
            var res1=JSON.parse(re);
             if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                   if(fr==1)
                                        location.href="{:url('index')}"
                                    else
                                        location.href="{:url('Workflowdb/index')}"
                                  //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                  //
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }      
        })
}
function zuofei(nodeKey,selectId,selectName){
  $("#nodeKey").val(nodeKey)
  $("#selectId").val(selectId)
  $("#selectName").val(selectName)
 
  var did={$data.id};
   $.ajax({
          cache: true,
          type: "POST",
          url:"{:url('zuofeichuli')}",
          data:"nodeKey="+nodeKey+"&selectId="+selectId+"&selectName="+selectName+"&id="+did,
          async: false,
          error: function(request) {
            alert("Connection error");
          },
          success: function(data) {
           //alert(data);
            //var res=JSON.parse(data);
                    var res1=JSON.parse(data);
                            if(res1["state"]==1){
                              swal({
                                title: "完成",
                                text: "操作已成功",
                                type: "success"
                                },function(){
                                   if(fr==1)
                                        location.href="{:url('index')}"
                                    else
                                        location.href="{:url('Workflowdb/index')}"
                                  //parent.layer.close(parent.layer.getFrameIndex(window.name))
                                  //
                                });

                          }else{
                            swal({
                            title: "错误",
                            text:  res1["msg"],
                            type: "warning"
                            });
                          }      
          }
        });
}
{/if}
    $(document).ready(function () {

        //添加促销方案
        $('.tjcxfa').on('click',function () {
            var bool = false
            $('.bc').each(function (i,o) {
                if($(this).is(':visible')){
                    bool = true
                }
            })
            if(bool){
                swal('请先保存促销方案')
                return false
            }
            var num = $('.fxfa:last').data('i')
            num++
            $('#cxfa_wrap').append('<form action="" class="form-inline"><table class="table-bordered table t_table fxfa">\n' +
                '                <input type="hidden" name="fa_id">\n' +
                '                <tr class="title_color">\n' +
                '                    <th style="min-width: 180px;width: 180px">促销方案'+num+'</th>\n' +
                '                    <th colspan="3">\n' +
                '                        <a href="javascript:;" class="shch">删除</a>\n' +
                '                        <a href="javascript:;" class="bc">保存</a>\n' +
                '                        <a href="javascript:;" class="bj" style="display: none;">编辑</a>\n' +
                '                    </th>\n' +
                '                </tr>\n' +
                '                <tr>\n' +
                '                    <td>是否整单<span class="colorRed">*</span></td>\n' +
                '                    <td>\n' +
                '                        <label for=""><input type="radio" name="sfzd_'+num+'" class="sfzd" value="1">是</label>\n' +
                '                        <label for=""><input type="radio" name="sfzd_'+num+'" class="sfzd" value="0" checked>否</label>\n' +
                '                    </td>\n' +
                '                    <td>\n' +
                '                        优惠时间段<span class="colorRed">*</span>\n' +
                '                    </td>\n' +
                '                    <td>\n' +
                '                        <div class="form-group">\n' +
                '                            <input type="text" class="form-control layer-date start"  style="display: inline-block;" name="start" value="" onclick="laydate({\n' +
                '        format: \'YYYY-MM-DD\',\n' +
                '//        min: laydate.now(), //设定最小日期为当前日期\n' +
                '        max: \'2099-06-16 23:59:59\', //最大日期\n' +
                '        istime: true,\n' +
                '        istoday: false,\n' +
                '    })">\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            至\n' +
                '                        </div>\n' +
                '                        <div class="form-group">\n' +
                '                            <input type="text" class="form-control layer-date end" style="display: inline-block;" name="end" value="" onclick="laydate({\n' +
                '        format: \'YYYY-MM-DD\',\n' +
                '//        min: laydate.now(), //设定最小日期为当前日期\n' +
                '        max: \'2099-06-16 23:59:59\', //最大日期\n' +
                '        istime: true,\n' +
                '        istoday: false,\n' +
                '    })">\n' +
                '                        </div>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '\n' +
                '                <tr>\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销区域<span class="colorRed">*</span>：</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        <div style="float:left;">\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="area_'+num+'" class="area" value="1" checked>分区\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="area_'+num+'" class="area" value="2" >省份\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="area_'+num+'" class="area" value="3" >城市\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="area_'+num+'" class="area" value="4" >经销商\n' +
                '                            </label>\n' +
                '                        </div>\n' +
                '                        <div style="width:300px;float:left;">\n' +
                '                            <div class="input-group">\n' +
                '                                <input class="area_id" type="text" placeholder="请输入关键字或空格查询"\n' +
                '                                       class="form-control" value="" style="min-width: 300px;width: 300px">\n' +
                '                                <div class="input-group-btn">\n' +
                '                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                '                                        <span class="caret"></span>\n' +
                '                                    </button>\n' +
                '                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                '                                    </ul>\n' +
                '                                </div>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <a href="javascript:;" style="float:left;margin-left:10px;" class="btn btn-primary select_area">选择</a>\n' +
                '                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;" >清空</button>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr>\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-right" id="selected_area">您选择的<span class="xuanding_name">分区</span><span class="colorRed">*</span>：</td>\n' +
                '                    <td id="xuanding" colspan="3">\n' +
                '                        <div class="duoxuan">\n' +
                '\n' +
                '                        </div>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="pro">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-right"><label for="">促销产品<span\n' +
                '                            class="colorRed">*</span>：</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        <div style="float:left;">\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="product_'+num+'" class="product" id="" value="1" checked>品牌\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="product_'+num+'" class="product" id="" value="2" >品类\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="product_'+num+'" class="product" id="" value="3" >系列\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="product_'+num+'" class="product" id="" value="4" >SKU\n' +
                '                            </label>\n' +
                '                            <label class="radio-inline">\n' +
                '                                <input type="radio" name="product_'+num+'" class="product" id="" value="5" >单品\n' +
                '                            </label>\n' +
                '                        </div>\n' +
                '                        <div style="width:300px;float:left;">\n' +
                '                            <div class="input-group">\n' +
                '                                <input class="product_id" type="text" placeholder="请输入关键字或空格查询" class="form-control" value="" style="min-width: 300px;width: 300px">\n' +
                '                                <div class="input-group-btn">\n' +
                '                                    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                '                                        <span class="caret"></span>\n' +
                '                                    </button>\n' +
                '                                    <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                '                                    </ul>\n' +
                '                                </div>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                        <a href="javascript:;" style="float:left;margin-left:10px;" class="btn btn-primary select_product">选择</a>\n' +
                '                        <button class="btn-danger empty" type="button" style="float:left;margin-left:10px;" >清空</button>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="pro">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-right" id="selected_product">您选择的<span class="xuanding_product">品牌</span><span class="colorRed">*</span>:</td>\n' +
                '                    <td class="xzd_brand" colspan="3">\n' +
                '                        <div class="duoxuan">\n' +
                '                        </div>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr>\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">优惠类型</label><span class="colorRed">*</span>:</td>\n' +
                '                    <td colspan="3">\n' +
                '                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="3" class="chzk">出货折扣</label>\n' +
                '                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="4" class="agdjch">按固定价出货</label>\n' +
                '                        <label for="" class="zdyc"><input type="checkbox" name="yhlx[]" value="5" class="shdz">随货搭赠</label>\n' +
                '                        <label for=""><input type="checkbox" name="yhlx[]" value="1" class="shmj">随货满减</label>\n' +
                '                        <label for=""><input type="checkbox" name="yhlx[]" value="2" class="chfd">出货返点</label>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="chzk_tr" style="display: none;">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货折扣</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        单位：\n' +
                '                        <select name="chzk_unit" class="dw2">\n' +
                '                            <option value="元">元</option>\n' +
                '                            <option value="发运单位">发运单位</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="chzk_tr" style="display: none;">\n' +
                '                    <td colspan="3">\n' +
                '                        <ul>\n' +
                '                            <li>\n' +
                '                                满 <input type="text" class="form-control" name="chzk_reach[]">（<span class="dw2_span">元</span>） <input name="chzk_down[]" type="text" class="form-control">%OFF,&nbsp;&nbsp;限量<input type="text" name="chzk_limit[]" class="form-control">（<span class="dw2_span">元</span>）\n' +
                '                                <a href="javascript:;" class="btn btn-default addit">+</a>\n' +
                '                            </li>\n' +
                '                        </ul>\n' +
                '\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="agdjch_tr" style="display: none;">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">按固定价出货</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        单位：\n' +
                '                        <select name="agdjch_unit" class="dw2">\n' +
                '                            <option value="元">元</option>\n' +
                '                            <option value="发运单位">发运单位</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="agdjch_tr" style="display: none;">\n' +
                '                    <td colspan="3">\n' +
                '                        <ul>\n' +
                '                            <li>\n' +
                '                                满 <input type="text" class="form-control" name="agdjch_reach[]">（<span class="dw2_span">元</span>） 按<input name="agdjch_down[]" type="text" class="form-control">（元/发运单位）出货,&nbsp;&nbsp;限量<input type="text" name="agdjch_limit[]" class="form-control">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit2">+</a>\n' +
                '                            </li>\n' +
                '                        </ul>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="shdz_tr" style="display: none;">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货搭赠</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        单位：\n' +
                '                        <select name="shdz_unit" class="dw2">\n' +
                '                            <option value="元">元</option>\n' +
                '                            <option value="发运单位">发运单位</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="shdz_tr" style="display: none;">\n' +
                '                    <td colspan="3">\n' +
                '                        <ul>\n' +
                '                            <li>\n' +
                '                                满 <input type="text" class="form-control" name="shdz_reach[]">（<span class="dw2_span">元</span>） 送赠品：<a href="javascript:;" class="shzhzp"><input type="hidden" name="shdz_gift[]" >设置赠品</a>,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shdz_limit[]">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit3">+</a><br>\n' +
                '                                <font color="red">请设置赠品</font>\n' +
                '                            </li>\n' +
                '                        </ul>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="shmj_tr" style="display: none;">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">随货满减</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        单位：\n' +
                '                        <select name="shmj_unit" class="dw1">\n' +
                '                            <option value="元">元</option>\n' +
                '                            <option value="发运单位">发运单位</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="shmj_tr" style="display: none;">\n' +
                '                    <td colspan="3">\n' +
                '                        <ul>\n' +
                '                            <li>\n' +
                '                                满 <input type="text" class="form-control" name="shmj_reach[]">（<span class="dw1_span">元</span>） 减 <input type="text" class="form-control" name="shmj_down[]">（<span class="dw1_span">元</span>）,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shmj_limit[]">（<span class="dw1_span">元</span>）<a href="javascript:;" class="btn btn-default addit4">+</a>\n' +
                '                            </li>\n' +
                '                        </ul>\n' +
                '\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="chfd_tr" style="display: none;">\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center" rowspan="2"><label for="">出货返点</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        单位：\n' +
                '                        <select name="chfd_unit" class="dw2">\n' +
                '                            <option value="元">元</option>\n' +
                '                            <option value="发运单位">发运单位</option>\n' +
                '                        </select>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr class="chfd_tr" style="display: none;">\n' +
                '                    <td colspan="3">\n' +
                '                        <ul>\n' +
                '                            <li>\n' +
                '                                满 <input type="text" class="form-control" name="chfd_reach[]">（<span class="dw2_span">元</span>） 减 <input type="text" class="form-control" name="chfd_down[]">%,&nbsp;&nbsp;限量<input type="text" class="form-control" name="chfd_limit[]">（<span class="dw2_span">元</span>）<a href="javascript:;" class="btn btn-default addit5">+</a>\n' +
                '                            </li>\n' +
                '                        </ul>\n' +
                '\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '                <tr>\n' +
                '                    <td style="min-width: 180px;width: 180px" class="text-center"><label for="">方案说明</label></td>\n' +
                '                    <td colspan="3">\n' +
                '                        <div class="ibox float-e-margins" style="margin-bottom: 0">\n' +
                '                            <div class="ibox-content no-padding">\n' +
                '                                <div class="summernote">\n' +
                '                                </div>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </td>\n' +
                '                </tr>\n' +
                '\n' +
                '            </table></form>')



            $(".area_id:last").bsSuggest({
                url:"{:url('Bs/zoning')}",
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).val('')
                var bool = false
                $(this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                    if ($(this).data('id') == keyword.id) {
                        bool = true;
                    }
                })
                if (bool == false)
                    $(this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                //console.log('onSetSelectValue: ', keyword, data);
            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });

            $(".product_id:last").bsSuggest({
                url: "{:url('Bs/brand')}",
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).val('')
                var $div = $(this).closest('table').find('.xzd_brand .duoxuan')
                var bool = false
                $div.find('.ren').each(function (idx, o) {
                    if ($(this).data('id') == keyword.id) {
                        bool = true;
                    }
                })
                if (bool == false){
                    $div.append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')

                }
                //console.log('onSetSelectValue: ', keyword, data);
            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });


            $('.summernote').summernote({
                lang: 'zh-CN'
            });

        })

        //设置赠品
        $('body').on('click','.shzhzp',function () {
            var _paymethod = $(this).closest('li').find('[name^=shdz_gift]')

            layer.open({
                type:2,
                area:['60%','60%'],
                title:'设置赠品',
                maxmin:true,
                content:'{:url("szzp")}',
                btn:'确定',
                btnAlign:'c',
                yes:function (i,o) {
                    var table1 = $(o).find('iframe').contents().find('#table1')
                    var data = []
                    if(table1.children('tbody').children('tr').length==0){
                        swal('请添加物料/物料再保存','','error')
                        return false
                    }
                    console.log(table1)
                    var bool = true
                    table1.children('tbody').children('tr').each(function (i,o) {
                        var wy = $(o).find('.wy:checked').val()
                        var product = $(o).find('[name=product]').val()
                        var product_title = $(o).find('.selectedOnlyOne .inin').text()
                        if(product==''){
                            swal('请选择样品或物料','','error')
                            bool = false
                            return false
                        }
                        var num = $(o).find('[name=num]').val()
                        if(num==''){
                            swal('请填写数量','','error')
                            bool = false
                            return false
                        }
                        var unit = $(o).find('.unit').text()
                        var price = $(o).find('.price').text()
                        var total = $(o).find('.total').text()
                        data.push({wy:wy,product:product,product_title:product_title,num:num,unit:unit,price:price,total:total})
                    })

                    if(bool == false){
                        return false
                    }

                    //字符串化并存储到select对象上
                    _paymethod.val(escape(JSON.stringify(data)))
                    //提交

                    layer.close(i)
                },
                success:function (o,i) {
                    var buhuo =  _paymethod.val()
                    buhuo = unescape(buhuo)
                    buhuo = JSON.parse(buhuo)
                    var table1 = $(o).find('iframe').contents().find('#table1')

                    for(var i = 0;i < buhuo.length;i++){
                        var checked = buhuo[i].wy==0?'checked':''
                        var checked2 = buhuo[i].wy==1?'checked':''
                        table1.children('tbody').append('<tr>\n' +
                            '            <td style="width:40%;">\n' +
                            '               <div class="col-xs-5">' +
                            '                <label for=""><input type="radio" name="'+name+'" class="wy" value="0" '+checked+'>样品</label>\n' +
                            '                <label for=""><input type="radio" name="'+name+'" class="wy" value="1" '+checked2+'>物料</label>' +
                            '               </div>\n' +
                            '               <div class="col-xs-7">'+
                            '                <div class="input-group show1" style="display:none">\n' +
                            '                    <input name="stuff" type="text" placeholder="请输入关键字或空格查询"\n' +
                            '                           class="input12 form-control sample" value="">\n' +
                            '                    <div class="input-group-btn">\n' +
                            '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                            '                            <span class="caret"></span>\n' +
                            '                        </button>\n' +
                            '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                            '                        </ul>\n' +
                            '                    </div>\n' +
                            '                </div>\n' +
                            '                <div class="input-group show2 col-xs-2" style="display: none;">\n' +
                            '                    <input name="stuff"  type="text" placeholder="请输入关键字或空格查询"\n' +
                            '                           class="input12 form-control material" value="">\n' +
                            '                    <div class="input-group-btn">\n' +
                            '                        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">\n' +
                            '                            <span class="caret"></span>\n' +
                            '                        </button>\n' +
                            '                        <ul class="dropdown-menu dropdown-menu-right" role="menu">\n' +
                            '                        </ul>\n' +
                            '                    </div>\n' +
                            '                </div>' +
                            '                <div class="selectedOnlyOne">\n' +
                            '                    <input type="hidden" name="product" value="'+buhuo[i].product+'">\n' +
                            '                    <span class="inin">'+buhuo[i].product_title+'</span>\n' +
                            '                    <span class="close">×</span>\n' +
                            '                </div>\n' +
                            '           </div>\n' +

                            '            </td>\n' +
                            '            <td>\n' +
                            '                <input type="text" name="num" value="'+buhuo[i].num+'">\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="unit">'+buhuo[i].unit+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="price">'+buhuo[i].price+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <span class="total">'+buhuo[i].total+'</span>\n' +
                            '            </td>\n' +
                            '            <td>\n' +
                            '                <button class="delete">删除</button>\n' +
                            '            </td>\n' +
                            '        </tr>');
                        var heji = _paymethod.closest('tr').find('input[name=amount]').val()
                        table1.find('#heji').html(heji)
                    }

                }
            })
            return false
        })

        //促销方案-删除
        $('body').on('click','.shch',function () {
            var _this = this
            if($('.fxfa').length==1){
                swal('至少有一条促销方案！')
                return false
            }
            var fa_id = $(this).closest('table').find('[name=fa_id]').val()
            if(fa_id){
                $.post('{:url("deletecxfa")}',{fa_id:fa_id},function(data){
                    if(data.success)
                        $(_this).closest('table').remove()
                },'json')
            }else{
                $(this).closest('table').remove()
            }
        })

        //促销方案-保存
        $('body').on('click','.bc',function () {
            var title = $('[name=title]').val()
            if(title==''){
                swal('请填写主题','','error')
                return false
            }

            var start = $(this).closest('table').find('[name=start]').val()
            if(start==''){
                swal('请填写优惠时间段','','error')
                return false
            }

            var end = $(this).closest('table').find('[name=end]').val()
            if(end==''){
                swal('请填写优惠时间段','','error')
                return false
            }

            var area_id = $(this).closest('table').find('[name^=area_id]').length
            if(area_id<1){
                if($('[name^=area]:checked').val()==1){
                    swal('请选择分区','','error')
                    return false
                }else if($('[name^=area]:checked').val()==2){
                    swal('请选择省份','','error')
                    return false
                }else if($('[name^=area]:checked').val()==3){
                    swal('请选择城市','','error')
                    return false
                }else if($('[name^=area]:checked').val()==4){
                    swal('请选择经销商','','error')
                    return false
                }

            }

            if($(this).closest('table').find('.sfzd:checked').val()=='0'){
                var product_id = $(this).closest('table').find('[name^=product_id]').length
                if(product_id<1){
                    if($(this).closest('table').find('[name^=product]:checked').val()==1){
                        swal('请选择品牌','','error')
                        return false
                    }else if($(this).closest('table').find('[name^=product]:checked').val()==2){
                        swal('请选择品类','','error')
                        return false
                    }else if($(this).closest('table').find('[name^=product]:checked').val()==3){
                        swal('请选择系列','','error')
                        return false
                    }else if($(this).closest('table').find('[name^=product]:checked').val()==4){
                        swal('请选择SKU','','error')
                        return false
                    }else if($(this).closest('table').find('[name^=product]:checked').val()==5){
                        swal('请选择单品','','error')
                        return false
                    }
                }
            }

            if($(this).closest('table').find('[name^=yhlx]:checked').length<1){
                swal('请选择优惠类型','','error')
                return false
            }

            var _this = this

            var param = $(this).closest('form').serialize()
            param += '&area='+$(this).closest('table').find('.area:checked').val()
            param += '&product='+$(this).closest('table').find('.product:checked').val()
            param += '&sfzd='+$(this).closest('table').find('.sfzd:checked').val()
            param += '&brief='+$(this).closest('table').find('.summernote').code()
            param += '&info='+$('#info').code()
            param += '&title='+$('[name=title]').val()
            param += '&sqr='+$('[name=sqr]').val()
            param += '&ssbm='+$('[name=ssbm]').val()
            param += '&sqtime='+$('[name=sqtime]').val()
            param += '&saleNum='+$('[name=saleNum]').val()
            param += '&policySaleNum='+$('[name=policySaleNum]').val()
            param += '&saleInc='+$('[name=saleInc]').val()
            param += '&estiGiftCost='+$('[name=estiGiftCost]').val()
            param += '&estiCostRate='+$('[name=estiCostRate]').val()
            param += '&estiReturnRate='+$('[name=estiReturnRate]').val()
            param += '&id='+$('[name=id]').val()
            param += '&attach='+$('[name=attach]').val()
            param += '&remove='+$('[name=remove]').val()
            //提交后台保存
           // $.post('{:url("savecxfa")}',param,function (data){alert(data)})
            $.post('{:url("savecxfa")}',param,function (data) {
                if(data.success){

                    /*$(_this).closest('table').find('input').attr('disabled',true)
                    $(_this).closest('table').find('select').attr('disabled',true)
                    $(_this).closest('table').find('textarea').attr('disabled',true)
                    $(_this).closest('table').find('.select_area').hide()
                    $(_this).closest('table').find('.empty').hide()
                    $(_this).closest('table').find('.select_product').hide()
                    $(_this).closest('table').find('.note-editable').attr('contenteditable',false)
                    $(_this).hide()
                    $(_this).closest('table').find('.bj').show()
                    $('input[name=id]').val(data.id)
                    $(_this).closest('table').find('input[name=fa_id]').val(data.fa_id)
                    */
                    location.href='{:url("update")}?id='+data.id
                }else{
                    swal(data.msg)
                }
            },'json')
            return false

        })  

        //点击编辑
        $('body').on('click','.bj',function () {
            var bool = false
            $('.bc').each(function (i,o) {
                if($(this).is(':visible')){
                    bool = true
                }
            })
            if(bool){
                swal('请先保存促销方案')
                return false
            }

            $(this).closest('table').removeClass('hideit')
            $(this).closest('table').find('input').attr('disabled',false)
            $(this).closest('table').find('select').attr('disabled',false)
            $(this).closest('table').find('textarea').attr('disabled',false)
            $(this).closest('table').find('.select_area').show()
            $(this).closest('table').find('.empty').show()
            $(this).closest('table').find('.select_product').show()
            $(this).closest('table').find('.note-editable').attr('contenteditable',true)
            $(this).hide()
            $(this).closest('table').find('.addit').show()
            $(this).closest('table').find('.addit2').show()
            $(this).closest('table').find('.addit3').show()
            $(this).closest('table').find('.addit4').show()
            $(this).closest('table').find('.addit5').show()
            $(this).closest('table').find('.delit').show()
            $(this).closest('table').find('.delit2').show()
            $(this).closest('table').find('.delit3').show()
            $(this).closest('table').find('.delit4').show()
            $(this).closest('table').find('.delit5').show()
            $(this).closest('table').find('.shzhzp').show()
            $(this).closest('table').find('.area_id').show()
            $(this).closest('table').find('.product_id').show()
            $(this).closest('table').find('.close').show()
            $(this).closest('table').find('.bc').show()
        })

        //是否整单
        $('body').on('click','.sfzd',function(){
            if($(this).val()=='1'){
                $(this).closest('table').find('.pro').hide()
                $(this).closest('table').find('.zdyc').hide()
            }else{
                $(this).closest('table').find('.pro').show()
                $(this).closest('table').find('.zdyc').show()

            }
        })

        //空
        $('body').on('click','.empty',function () {
            $(this).closest('tr').next('tr').find('.duoxuan').html('')
        })

        //产品
        $(".product_id").each(function (i,o) {
            var tmp_link
            switch($(o).closest('tr').find('.product:checked').val()){
                case '2':
                    tmp_link = "{:url('Bs/category')}"
                    break
                case '3':
                    tmp_link = "{:url('Bs/series')}"
                    break
                case '4':
                    tmp_link = "{:url('Bs/sku')}"
                    break
                case '5':
                    tmp_link = "{:url('Bs/product')}"
                    break
                default:
                    tmp_link = "{:url('Bs/brand')}"
            }

            $(o).bsSuggest({
                url: tmp_link,
                effectiveFields: ["id", "title"],
                searchFields: [ "title"],
                effectiveFieldsAlias: {title: "名称"},
                ignorecase: true,
                showHeader: true,
                showBtn: false,     //不显示下拉按钮
                delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                idField: "id",
                keyField: "title",
                clearable: true
            }).on('onDataRequestSuccess', function (e, result) {
                console.log('onDataRequestSuccess: ', result);
            }).on('onSetSelectValue', function (e, keyword, data) {
                $(this).val('')
                var $div = $(this).closest('table').find('.xzd_brand .duoxuan')
                var bool = false
                $div.find('.ren').each(function (idx, o) {
                    if ($(this).data('id') == keyword.id) {
                        bool = true;
                    }
                })
                if (bool == false){
                    $div.append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')

                }
                //console.log('onSetSelectValue: ', keyword, data);
            }).on('onUnsetSelectValue', function () {
                console.log("onUnsetSelectValue");
            });
        })

        $('body').on('change','.dw1',function () {
            $(this).closest('tr').next('tr').find('.dw1_span').html($(this).val())
        })
        //单位2
        $('body').on('change','.dw2',function () {
            $(this).closest('tr').next('tr').find('.dw2_span').html($(this).val())
        })
        $('body').on('click','.shmj',function () {
            if($(this).prop('checked') == true)
                $(this).closest('table').find('.shmj_tr').show()
            else
                $(this).closest('table').find('.shmj_tr').hide()

        })
        $('body').on('click','.chfd',function () {
            if($(this).prop('checked') == true)
                $(this).closest('table').find('.chfd_tr').show()
            else
                $(this).closest('table').find('.chfd_tr').hide()
        })
        $('body').on('click','.chzk',function () {
            if($(this).prop('checked') == true){
                if($(this).closest('table').find('.agdjch').prop('checked')){
                    swal('出货折扣和按固定价出货不能同时存在')
                    return false
                }
                $(this).closest('table').find('.chzk_tr').show()
            }else
                $(this).closest('table').find('.chzk_tr').hide()
        })
        $('body').on('click','.agdjch',function () {
            if($(this).prop('checked') == true){
                if($(this).closest('table').find('.chzk').prop('checked')){
                    swal('出货折扣和按固定价出货不能同时存在')
                    return false
                }
                $(this).closest('table').find('.agdjch_tr').show()
            }else
                $(this).closest('table').find('.agdjch_tr').hide()
        })
        $('body').on('click','.shdz',function () {
            if($(this).prop('checked') == true)
                $(this).closest('table').find('.shdz_tr').show()
            else
                $(this).closest('table').find('.shdz_tr').hide()
        })
        $('.summernote').summernote({
            lang: 'zh-CN'
        });
        $('.summernote_disabled+.note-editor .note-editable').prop('contenteditable', false)
    });
   /* //日期范围限制
    var start = {
        elem: '#start',
        format: 'YYYY-MM-DD',
//        min: laydate.now(), //设定最小日期为当前日期
        max: '2099-06-16 23:59:59', //最大日期
        istime: true,
        istoday: false,
        choose: function (datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#end',
        format: 'YYYY-MM-DD',
//        min: laydate.now(),
        max: '2099-06-16 23:59:59',
        istime: true,
        istoday: false,
        choose: function (datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);*/

    function back() {
        history.go(-1);
    }

    /*表单只能输出数字*/
    var numReg = document.getElementsByClassName('numReg');
    for (var i = 0; i < numReg.length; i++) {
        numReg[i].onkeyup = function () {
            this.value = this.value.replace(/[^\d]/g, '');
        }
    }

    $('input[name=policySaleNum]').on('input',function () {
        var policySaleNum = $(this).val()
        var saleNum = $('input[name=saleNum]').val()
        var saleInc = parseFloat(policySaleNum)-parseFloat(saleNum)
        $('[name=saleInc]').val(saleInc)
        $('#saleIncSpan').html(saleInc)
    })

    $('input[name=estiGiftCost]').on('input',function () {
        var policySaleNum = $('[name=policySaleNum]').val()
        var saleInc = $('input[name=saleInc]').val()
        var estiGiftCost = $(this).val()
        estiCostRate = (parseFloat(estiGiftCost)/parseFloat(policySaleNum)*100).toFixed(2)
        $('#estiCostRateSpan').html(estiCostRate)
        $('[name=estiCostRate]').val(estiCostRate)
        estiReturnRate = (parseFloat(saleInc)/parseFloat(estiGiftCost)*100).toFixed(2)
        $('#estiReturnRateSpan').html(estiReturnRate)
        $('[name=estiReturnRate]').val(estiReturnRate)
    })

    //区域
    $('body').on('click','.area',function () {
        var _this = this
        var val = $(this).val()
        switch (val){
            case '1':
                if($(_this).closest('table').find('.xuanding_name').html()!='分区'){
                    $(_this).closest('table').find('.xuanding_name').html('分区')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.area_id').val('')
                    $(_this).closest('tr').find(".area_id").bsSuggest("destroy");
                    $(_this).closest('tr').find(".area_id").bsSuggest({
                        url: "{:url('Bs/zoning')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan').find('.ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_area').off('click')
                    $(_this).closest('tr').find('.select_area').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("select/zoning")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="area_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '2':
                if($(_this).closest('table').find('.xuanding_name').html()!='省份'){
                    $(_this).closest('table').find('.xuanding_name').html('省份')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.area_id').val('')
                    $(_this).closest('tr').find('.area_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.area_id').bsSuggest({
                        url: "{:url('Bs/provice')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_area').off('click')
                    $(_this).closest('tr').find('.select_area').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/provice")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="area_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '3':
                if($(_this).closest('table').find('.xuanding_name').html()!='城市'){
                    $(_this).closest('table').find('.xuanding_name').html('城市')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.area_id').val('')
                    $(_this).closest('tr').find('.area_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.area_id').bsSuggest({
                        url: "{:url('Bs/city')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_area').off('click')
                    $(_this).closest('tr').find('.select_area').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/city")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="area_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '4':
                if($(_this).closest('table').find('.xuanding_name').html()!='经销商'){
                    $(_this).closest('table').find('.xuanding_name').html('经销商')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.area_id').val('')
                    $(_this).closest('tr').find('.area_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.area_id').bsSuggest({
                        url: "{:url('Bs/jxs')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_area').off('click')
                    $(_this).closest('tr').find('.select_area').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/jxs")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="area_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
        }
    })

    //区域id
    $(".area_id").each(function (i,o) {
        var tmp_link
        switch($(o).closest('tr').find('.area:checked').val()){
            case '2':
                tmp_link = "{:url('Bs/provice')}"
                break
            case '3':
                tmp_link = "{:url('Bs/city')}"
                break
            case '4':
                tmp_link = "{:url('Bs/jxs')}"
                break
            default:
                tmp_link = "{:url('Bs/zoning')}"
        }

        $(o).bsSuggest({
            url: tmp_link,
            effectiveFields: ["id", "title"],
            searchFields: [ "title"],
            effectiveFieldsAlias: {title: "名称"},
            ignorecase: true,
            showHeader: true,
            showBtn: false,     //不显示下拉按钮
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            idField: "id",
            keyField: "title",
            clearable: true
        }).on('onDataRequestSuccess', function (e, result) {
            console.log('onDataRequestSuccess: ', result);
        }).on('onSetSelectValue', function (e, keyword, data) {
            $(this).val('')
            var bool = false
            $(this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                if ($(this).data('id') == keyword.id) {
                    bool = true;
                }
            })
            if (bool == false)
                $(this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="area_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
            //console.log('onSetSelectValue: ', keyword, data);
        }).on('onUnsetSelectValue', function () {
            console.log("onUnsetSelectValue");
        });

    })


    //删除单个选定
    $('body').on('click','.duoxuan .close',function () {

        $(this).closest('.ren').remove()
    })

    //促销产品
    $('body').on('click','.product',function () {
        var _this = this
        var val = $(this).val()
        switch (val){
            case '1':
                if($(_this).closest('table').find('.xuanding_product').html()!='品牌'){
                    $(_this).closest('table').find('.xuanding_product').html('品牌')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.product_id').val('')
                    $(_this).closest('tr').find(".product_id").bsSuggest("destroy");
                    $(_this).closest('tr').find(".product_id").bsSuggest({
                        url: "{:url('Bs/brand')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan').find('.ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_product').off('click')
                    $(_this).closest('tr').find('.select_product').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/brand")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '2':
                if($(_this).closest('table').find('.xuanding_product').html()!='品类'){
                    $(_this).closest('table').find('.xuanding_product').html('品类')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.product_id').val('')
                    $(_this).closest('tr').find('.product_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.product_id').bsSuggest({
                        url: "{:url('Bs/category')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_product').off('click')
                    $(_this).closest('tr').find('.select_product').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/category")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '3':
                if($(_this).closest('table').find('.xuanding_product').html()!='系列'){
                    $(_this).closest('table').find('.xuanding_product').html('系列')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.product_id').val('')
                    $(_this).closest('tr').find('.product_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.product_id').bsSuggest({
                        url: "{:url('Bs/series')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_product').off('click')
                    $(_this).closest('tr').find('.select_product').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/series")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '4':
                if($(_this).closest('table').find('.xuanding_product').html()!='SKU'){
                    $(_this).closest('table').find('.xuanding_product').html('SKU')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.product_id').val('')
                    $(_this).closest('tr').find('.product_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.product_id').bsSuggest({
                        url: "{:url('Bs/sku')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_product').off('click')
                    $(_this).closest('tr').find('.select_product').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/sku")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
            case '5':
                if($(_this).closest('table').find('.xuanding_product').html()!='单品'){
                    $(_this).closest('table').find('.xuanding_product').html('单品')
                    $(_this).closest('tr').next('tr').find('.duoxuan').html('')
                    $(_this).closest('tr').find('.product_id').val('')
                    $(_this).closest('tr').find('.product_id').bsSuggest("destroy");
                    $(_this).closest('tr').find('.product_id').bsSuggest({
                        url: "{:url('Bs/products')}",
                        effectiveFields: ["id", "title"],
                        searchFields: [ "title"],
                        effectiveFieldsAlias: {title: "名称"},
                        ignorecase: true,
                        showHeader: true,
                        showBtn: false,     //不显示下拉按钮
                        delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
                        idField: "id",
                        keyField: "title",
                        clearable: true
                    }).on('onSetSelectValue', function (e, keyword, data) {
                        $(this).val('')
                        var bool = false
                        $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                            if ($(this).data('id') == keyword.id) {
                                bool = true;
                            }
                        })
                        if (bool == false)
                            $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + keyword.id + '">' + keyword.key + '<input type="hidden" name="product_id[]" value="' + keyword.id + '"><span class="close">×</span></span>')
                    });
                    $(_this).closest('tr').find('.select_product').off('click')
                    $(_this).closest('tr').find('.select_product').on('click',function () {
                        layer.open({
                            type: 2,
                            title: '&nbsp;',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['800px', '500px'],
                            content: '{:url("open/product")}',
                            btn:['确定','关闭'],
                            yes:function (i,o) {
                                var a = $(o).find('iframe').contents()
                                var data = a.find('#data')
                                data = data.val()
                                data = JSON.parse(data)
                                var bool = false
                                for(var j=0;j<data.length;j++){
                                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                                        if ($(this).data('id') == data[j].id) {
                                            bool = true;
                                        }
                                    })
                                    if (bool == false)
                                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                                }
                                layer.close(i)
                            }
                        })
                    })
                }
                break;
        }
    })

    //选择区域
    $('body').on('click','.select_area',function () {

        var tmp_link
        switch($(this).closest('tr').find('.area:checked').val()){
            case '2':
                tmp_link = "{:url('open/provice')}"
                break
            case '3':
                tmp_link = "{:url('open/city')}"
                break
            case '4':
                tmp_link = "{:url('open/jxs')}"
                break
            default:
                tmp_link = "{:url('select/zoning')}"
        }

        var _this = this
        layer.open({
            type: 2,
            title: '&nbsp;',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '500px'],
            content: tmp_link,
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()
                var data = a.find('#data')
                data = data.val()
                data = JSON.parse(data)
                var bool = false
                for(var j=0;j<data.length;j++){
                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                        if ($(this).data('id') == data[j].id) {
                            bool = true;
                        }
                    })
                    if (bool == false)
                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="area_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                }
                layer.close(i)
            }
        })
    })

    //选择产品
    $('body').on('click','.select_product',function () {
        var tmp_link
        switch($(".product_id").closest('tr').find('.area:checked').val()){
            case 2:
                tmp_link = "{:url('open/category')}"
                break
            case 3:
                tmp_link = "{:url('open/series')}"
                break
            case 4:
                tmp_link = "{:url('open/sku')}"
                break
            case 5:
                tmp_link = "{:url('open/product')}"
                break
            default:
                tmp_link = "{:url('open/brand')}"
        }

        var _this = this
        layer.open({
            type: 2,
            title: '&nbsp;',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['800px', '500px'],
            content: tmp_link,
            btn:['确定','关闭'],
            yes:function (i,o) {
                var a = $(o).find('iframe').contents()
                var data = a.find('#data')
                data = data.val()
                data = JSON.parse(data)
                var bool = false
                for(var j=0;j<data.length;j++){
                    $(_this).closest('tr').next('tr').find('.duoxuan .ren').each(function (idx, o) {
                        if ($(this).data('id') == data[j].id) {
                            bool = true;
                        }
                    })
                    if (bool == false)
                        $(_this).closest('tr').next('tr').find('.duoxuan').append('<span class="ren" data-id="' + data[j].id + '">' + data[j].title + '<input type="hidden" name="product_id[]" value="' + data[j].id + '"><span class="close">×</span></span>')
                }
                layer.close(i)
            }
        })
    })

    //提交
    $('.save').on('click',function () {
        var savetype = $(this).prop('id')

        var param = {}
        param.title = $('[name=title]').val()
        param.sqr = $('[name=sqr]').val()
        param.ssbm = $('[name=ssbm]').val()
        param.sqtime = $('[name=sqtime]').val()
        param.info = $('#info').code()
        param.saleNum = $('[name=saleNum]').val()
        param.policySaleNum = $('[name=policySaleNum]').val()
        param.saleInc = $('[name=saleInc]').val()
        param.estiGiftCost = $('[name=estiGiftCost]').val()
        param.estiCostRate = $('[name=estiCostRate]').val()
        param.estiReturnRate = $('[name=estiReturnRate]').val()
        param.attach = $('[name=attach]').val()
        param.remove = $('[name=remove]').val()
        param.id = $('[name=id]').val()
        param.savetype = savetype
        $.post('',param,function (data) {
            if(data.success){
                swal({'title':data.msg,'type':'success'},function () {
                    location.href='{:url("index")}'
                })
            }else{
                swal(data.msg)
            }
        },'json')
    })

</script>
<script>
    $(function () {
        //出货折扣增加行
        $('body').on('click','.addit',function () {
            var unit = $(this).closest('tr').prev('tr').find('[name=chzk_unit]').val()
            $(this).closest('ul').append('<li>满 <input type="text" class="form-control" name="chzk_reach[]" value="">（<span class="dw2_span">'+unit+'</span>） <input name="chzk_down[]" type="text" class="form-control" value="">%OFF,&nbsp;&nbsp;限量<input type="text" name="chzk_limit[]" class="form-control" value="">（<span class="dw2_span">'+unit+'</span>）<a href="javascript:;" class="btn btn-default delit">-</a><a href="javascript:;" class="btn btn-default addit">+</a></li>')
            if( $(this).closest('li').is(':first-child') && $(this).closest('li').has('.delit') ){
                $(this).closest('li').find('.delit').remove()
            }
            $(this).remove()
        })
        //出货折扣删除行
        $('body').on('click','.delit',function () {
            if($(this).closest('li').is(':last-child')){
                if($(this).closest('li').is(':first-child')){
                    swal('至少保留一行！')
                    return false
                }else{
                    $(this).closest('li').prev('li').append('<a href="javascript:;" class="btn btn-default addit">+</a>')
                }
            }
            $(this).closest('li').remove()
        })
        //按固定价出货增加行
        $('body').on('click','.addit2',function () {
            var unit = $(this).closest('tr').prev('tr').find('[name=agdjch_unit]').val()
            $(this).closest('ul').append('<li>满 <input type="text" class="form-control" name="agdjch_reach[]" value="">（<span class="dw2_span">'+unit+'</span>） 按<input name="agdjch_down[]" type="text" class="form-control" value="">（元/发运单位）出货,&nbsp;&nbsp;限量<input type="text" name="agdjch_limit[]" class="form-control" value="">（<span class="dw2_span">'+unit+'</span>）<a href="javascript:;" class="btn btn-default delit2">-</a><a href="javascript:;" class="btn btn-default addit2">+</a></li>')
            if( $(this).closest('li').is(':first-child') && $(this).closest('li').has('.delit') ){
                $(this).closest('li').find('.delit').remove()
            }
            $(this).remove()
        })
        //按固定价出货删除行
        $('body').on('click','.delit2',function () {
            if($(this).closest('li').is(':last-child')){
                if($(this).closest('li').is(':first-child')){
                    swal('至少保留一行！')
                    return false
                }else{
                    $(this).closest('li').prev('li').append('<a href="javascript:;" class="btn btn-default addit2">+</a>')
                }
            }
            $(this).closest('li').remove()
        })
        //随货搭赠增加行
        $('body').on('click','.addit3',function () {
            var unit = $(this).closest('tr').prev('tr').find('[name=shdz_unit]').val()
            $(this).closest('ul').append('<li>满 <input type="text" class="form-control" name="shdz_reach[]">（<span class="dw2_span">'+unit+'</span>） 送赠品：<a href="javascript:;" class="shzhzp"><input type="hidden" name="shdz_gift[]" >设置赠品</a>,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shdz_limit[]">（<span class="dw2_span">'+unit+'</span>）<a href="javascript:;" class="btn btn-default delit3">-</a><a href="javascript:;" class="btn btn-default addit3">+</a><br><font color="red">请设置赠品</font></li>')
            if( $(this).closest('li').is(':first-child') && $(this).closest('li').has('.delit') ){
                $(this).closest('li').find('.delit').remove()
            }
            $(this).remove()
        })
        //随货搭赠删除行
        $('body').on('click','.delit3',function () {
            if($(this).closest('li').is(':last-child')){
                if($(this).closest('li').is(':first-child')){
                    swal('至少保留一行！')
                    return false
                }else{
                    $(this).closest('li').prev('li').find('br').before('<a href="javascript:;" class="btn btn-default addit3">+</a>')
                }
            }
            $(this).closest('li').remove()
        })

        //随货满减增加行
        $('body').on('click','.addit4',function () {
            var unit = $(this).closest('tr').prev('tr').find('[name=shmj_unit]').val()
            $(this).closest('ul').append('<li>满 <input type="text" class="form-control" name="shmj_reach[]">（<span class="dw1_span">'+unit+'</span>） 减 <input type="text" class="form-control" name="shmj_down[]">（<span class="dw1_span">'+unit+'</span>）,&nbsp;&nbsp;限量<input type="text" class="form-control" name="shmj_limit[]">（<span class="dw1_span">'+unit+'</span>）<a href="javascript:;" class="btn btn-default delit4">-</a><a href="javascript:;" class="btn btn-default addit4">+</a></li>')
            if( $(this).closest('li').is(':first-child') && $(this).closest('li').has('.delit') ){
                $(this).closest('li').find('.delit').remove()
            }
            $(this).remove()
        })
        //随货满减删除行
        $('body').on('click','.delit4',function () {
            if($(this).closest('li').is(':last-child')){
                if($(this).closest('li').is(':first-child')){
                    swal('至少保留一行！')
                    return false
                }else{
                    $(this).closest('li').prev('li').append('<a href="javascript:;" class="btn btn-default addit4">+</a>')
                }
            }
            $(this).closest('li').remove()
        })

        //出货返点增加行
        $('body').on('click','.addit5',function () {
            var unit = $(this).closest('tr').prev('tr').find('[name=chfd_unit]').val()
            $(this).closest('ul').append('<li>满 <input type="text" class="form-control" name="chfd_reach[]">（<span class="dw2_span">'+unit+'</span>） 减 <input type="text" class="form-control" name="chfd_down[]">%,&nbsp;&nbsp;限量<input type="text" class="form-control" name="chfd_limit[]">（<span class="dw2_span">'+unit+'</span>）<a href="javascript:;" class="btn btn-default delit5">-</a><a href="javascript:;" class="btn btn-default addit5">+</a></li>')
            if( $(this).closest('li').is(':first-child') && $(this).closest('li').has('.delit') ){
                $(this).closest('li').find('.delit').remove()
            }
            $(this).remove()
        })

        //出货返点删除行
        $('body').on('click','.delit5',function () {
            if($(this).closest('li').is(':last-child')){
                if($(this).closest('li').is(':first-child')){
                    swal('至少保留一行！')
                    return false
                }else{
                    $(this).closest('li').prev('li').append('<a href="javascript:;" class="btn btn-default addit5">+</a>')
                }
            }
            $(this).closest('li').remove()
        })
    })
</script>
</body>
<!-- Web Uploader -->
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
    var upload_url = '{:url("upload/fileupload")}';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script src="__STATIC__/layout/js/upload.js"></script>
</html>
